<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>签到天数统计</title>
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css">
</head>
<body>
<div class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">主题切换</label>
        <div class="layui-input-block">
            <input type="checkbox" lay-filter="encrypt" name="switch" lay-skin="switch" lay-text="明亮模式|深色模式">
        </div>
    </div>
</div>

<div id="main" style="width: 1300px;height: 500px;"></div>

<script type="text/javascript" src="layui/layui.js"></script>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="common/jquery-1.8.3.js"></script>
<script type="text/javascript" src="echarts/echarts.min.js"></script>
<script type="text/javascript">

    $.ajax({
        url:'statistic/sign',
        type:'get',
        dataType:'json',
        success:function (result) {
            if (result.code == 200) {
                myChart.setOption({
                    xAxis: {
                        data: ['签到0天','签到1天','签到2天','签到3天','签到4天','签到5天','签到6天','签到7天及以上']
                    },
                    series: [{
                        name:'人数',
                        type: 'bar',
                        data: [{
                            value: result.data.days0,
                            itemStyle: {
                                color: '#009688'
                            }
                        }, {
                            value: result.data.days1,
                            itemStyle: {
                                color: '#FF0000'
                            }
                        }, {
                            value: result.data.days2,
                            itemStyle: {
                                color: '#FF7F00'
                            }
                        }, {
                            value: result.data.days3,
                            itemStyle: {
                                color: '#FFFF00'
                            }
                        }, {
                            value: result.data.days4,
                            itemStyle: {
                                color: '#00FF00'
                            }
                        }, {
                            value: result.data.days5,
                            itemStyle: {
                                color: '#00FFFF'
                            }
                        }, {
                            value: result.data.days6,
                            itemStyle: {
                                color: '#0000FF'
                            }
                        }, {
                            value: result.data.days7,
                            itemStyle: {
                                color: '#8B00FF'
                            }
                        }]
                    }]
                });
            }
        }
    })

    // 基于准备好的dom，初始化echarts实例
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);
    myChart.resize();
    // 指定图表的配置项和数据
    var option = {
        title: {
            text: '用户累计签到天数统计'
        },
        tooltip: {},
        legend: {
            data:['人数']
        },
        xAxis: {
            data: []
        },
        yAxis: {},
        series: [{
            name: '人数',
            type: 'bar',
            data: []
        }]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);

    //3秒钟刷新一次
    setInterval(function () {
        $.ajax({
            url:'statistic/sign',
            type:'get',
            dataType:'json',
            success:function (result) {
                if (result.code == 200) {
                    myChart.setOption({
                        xAxis: {
                            data: ['签到0天','签到1天','签到2天','签到3天','签到4天','签到5天','签到6天','签到7天及以上']
                        },
                        series: [{
                            name:'人数',
                            type: 'bar',
                            data: [{
                                value: result.data.days0,
                                itemStyle: {
                                    color: '#009688'
                                }
                            }, {
                                value: result.data.days1,
                                itemStyle: {
                                    color: '#FF0000'
                                }
                            }, {
                                value: result.data.days2,
                                itemStyle: {
                                    color: '#FF7F00'
                                }
                            }, {
                                value: result.data.days3,
                                itemStyle: {
                                    color: '#FFFF00'
                                }
                            }, {
                                value: result.data.days4,
                                itemStyle: {
                                    color: '#00FF00'
                                }
                            }, {
                                value: result.data.days5,
                                itemStyle: {
                                    color: '#00FFFF'
                                }
                            }, {
                                value: result.data.days6,
                                itemStyle: {
                                    color: '#0000FF'
                                }
                            }, {
                                value: result.data.days7,
                                itemStyle: {
                                    color: '#8B00FF'
                                }
                            }]
                        }]
                    });
                }
            }
        })
    }, 3000);


    layui.use('form', function(){
        var form = layui.form;

        form.render('checkbox');

        form.on('switch(encrypt)', function(data){

            if (data.elem.checked == true) {
                $("html").css("background-color", "#fff")
                $("body").css("filter", "invert(1) hue-rotate(270deg)")
                $("body").css("background-color", "#fff");
            }else {
                $("body").css("background-color", "");
                $("body").css("filter", "")
                $("html").css("background-color", "")
            }

        });
    });
</script>
</body>
</html>